package com.ltedu.oss.storage;

import com.ltedu.oss.storage.impl.QiniuStorageImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @className: StorageFactory
 * @auther: Jerry
 * @date: 2020/11/26 14:06
 * @desctiption: 文件存储工厂
 * @version: 1.0
 */
@Component
public class StorageFactory {

    @Autowired
    private ApplicationContext applicationContext;

    private Map<String, Storage> fileRepoMap = new HashMap<>();

    @PostConstruct
    public void init() {
//        fileRepoMap.put("native", applicationContext.getBean(NativeStorageImpl.class));
//        fileRepoMap.put("upyun", applicationContext.getBean(UpYunStorageImpl.class));
//        fileRepoMap.put("aliyun", applicationContext.getBean(AliyunStorageImpl.class));
        fileRepoMap.put("qiniu", applicationContext.getBean(QiniuStorageImpl.class));
    }

    public Storage get(String scheme) {
        return fileRepoMap.get(scheme);
    }
}
